/**
 * Created with IntelliJ IDEA.
 * User: NM Group
 * Date: 06.09.12
 * Time: 17:41
 * To change this template use File | Settings | File Templates.
 */
package com.samoiloff.framework.controller {
import com.samoiloff.framework.AbstractView;
import com.samoiloff.framework.model.AbstractInitModel;
import com.samoiloff.framework.model.AbstractModel;

import flash.events.Event;

public class AbstractInitController extends AbstractController {

	private var _cModel : AbstractInitModel;

	public function AbstractInitController(view:AbstractView) {
		super(view);

		_cModel = view.model as AbstractInitModel;

		if (_cModel.initialized) {
			onInitialized();
		} else {
			_cModel.addEventListener(AbstractInitModel.INITIALIZED_CHANGED, onInitialized);
		}
	}


	override public function destroy():void {
		_cModel.removeEventListener(AbstractInitModel.INITIALIZED_CHANGED, onInitialized);
		_cModel = null;

		super.destroy();
	}

	protected function onInitialized(event:Event = null):void {
		_cModel.removeEventListener(AbstractInitModel.INITIALIZED_CHANGED, onInitialized);

	}
}
}
